package models

import "time"

type DicomInfo struct {
	ID                uint `gorm:"primarykey"`
	PatientID         string
	AccessionNumber   string
	PatientName       string
	SeriesDate        string
	SeriesTime        string
	StudyDate         string
	StudyTime         string
	AcquisitionDate   string
	AcquisitionTime   string
	StudyInstanceUID  string
	SeriesInstanceUID string
	StudyID           string
	SeriesNumber      string
	InstanceNumber    string
	FileInfoID        uint

	CreatedAt time.Time
	UpdatedAt time.Time
}

//func NewDicom(patientID, accessionNumber, patientName, seriesDate, seriesTime, studyDate, studyTime, acquisitionDate, acquisitionTime, studyInstanceUID, seriesInstanceUID, studyID string, seriesNumber string, instanceNumber string, file uint) *DicomInfo {
//	return &DicomInfo{
//		PatientID:         patientID,
//		AccessionNumber:   accessionNumber,
//		PatientName:       patientName,
//		SeriesDate:        seriesDate,
//		SeriesTime:        seriesTime,
//		StudyDate:         studyDate,
//		StudyTime:         studyTime,
//		AcquisitionDate:   acquisitionDate,
//		AcquisitionTime:   acquisitionTime,
//		StudyInstanceUID:  studyInstanceUID,
//		SeriesInstanceUID: seriesInstanceUID,
//		StudyID:           studyID,
//		SeriesNumber:      seriesNumber,
//		InstanceNumber:    instanceNumber,
//		FileInfoID:        file,
//	}
//}

func (d *DicomInfo) clear() {
	DBConn.Exec("DELETE FROM dicom_infos")
	Log.WARNING("clear DB dicom_infos  table is over~!")
}

func (d *DicomInfo) InsertOne() {
	result := DBConn.FirstOrCreate(d, d)
	if result.RowsAffected <= 0 {
		Log.WARNING("重复录入: %v", d.FileInfoID)
		return
	} else if result.Error != nil {
		Log.WARNING("数据写入异常：%v", d.FileInfoID)
		return
	}
	Log.INFO("FileInfoID:%v  写入dicom表完成～！", d.FileInfoID)
}

// func (d *DicomInfo) Insert() {
// 	result := DBConn.Create(d)
// 	if result.RowsAffected <= 0 {
// 		Log.WARNING("重复录入: %v", d.FileInfoID)
// 		return
// 	} else if result.Error != nil {
// 		Log.WARNING("数据写入异常：%v", d.FileInfoID)
// 		return
// 	}
// 	Log.INFO("FileInfoID:%v 写表完成～！", d.FileInfoID)
// }
